package com.mediatek.factorymode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.content.ComponentName;
import android.app.AlertDialog;
import android.content.DialogInterface;  

import com.mediatek.factorymode.version.version;  


public class MainActivity extends ListActivity {
	

	private ListView mListView;
	private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
	private boolean isShortCut;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		
		setContentView(R.layout.main_listview);
		mListView = getListView();
        isShortCut = getIntent().getBooleanExtra("shortcut",false);
		//mListView.setBackgroundDrawable(getResources().getDrawable(R.drawable.main_screen_bg));
		//mListView.setCacheColorHint(0);
		
		
		list = new ArrayList<Map<String,Object>>(); 
        
        Map<String,Object> hashmap = new HashMap<String,Object>(); 

        hashmap.put("picture",R.drawable.ui_1); 
        hashmap.put("title",getString(R.string.manu_test)); 
        list.add(hashmap); 
        
        hashmap = new HashMap<String,Object>(); 
        hashmap.put("picture",R.drawable.ui_2); 
        hashmap.put("title",getString(R.string.auto_test)); 
        list.add(hashmap); 
        
        
        hashmap = new HashMap<String,Object>(); 
        hashmap.put("picture",R.drawable.ui_3); 
        hashmap.put("title",getString(R.string.Report)); 
        list.add(hashmap); 
        
        hashmap = new HashMap<String,Object>(); 
        hashmap.put("picture",R.drawable.ui_4); 
        hashmap.put("title",getString(R.string.version)); 
        list.add(hashmap); 
        
        

		SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(),
				list, R.xml.picture_title_main, new String[] { "picture", "title" },
				new int[] { R.id.picture, R.id.title });

		mListView.setAdapter(adapter);

	}
	
    protected void onListItemClick(ListView lv,View view,int posititon,long id){
    	super.onListItemClick(lv, view, posititon, id);
    	if(view == null) return;
    	Intent app_intent;
    	switch(posititon){
    		case 0:
    			app_intent = new Intent(MainActivity.this, FactoryMode.class);
        		startActivity(app_intent);
    			break;
    		case 1:
    			app_intent = new Intent(MainActivity.this, AutoTest.class);
        		startActivity(app_intent);
    			break;
    		case 2:
    			app_intent = new Intent(MainActivity.this, Report.class);
        		startActivity(app_intent);
    			break;
    		case 3:
                app_intent = new Intent(MainActivity.this, version.class);
                startActivity(app_intent);		
    			break;

    	}
    }
    
    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        android.util.Log.i("xxczy","---onCreate---"+isShortCut);
        if(isShortCut){
            startFactory();
            isShortCut = false;
        }
    }

    private void startFactory(){
        Intent intent = new Intent();
        intent.setClassName("com.mediatek.factorymode","com.mediatek.factorymode.FactoryMode");
        startActivity(intent);
    } 
}